package com.example.clinic.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wyl.clinic.common.QueryPageParam;
import com.wyl.clinic.common.Result;
import com.example.clinic.entity.Patient;
import com.example.clinic.service.PatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 病人表 前端控制器
 * </p>
 *
 * @author wangyulong
 * @since 2024-02-03
 */
@RestController
@RequestMapping("/patient")
public class PatientController {

    @Autowired
    private PatientService patientService;

    @GetMapping("/list")
    public List<Patient> list(){
        return patientService.list();
    }




    @PostMapping("/listPage")
    public Result listPage(@RequestBody QueryPageParam query){
        HashMap param = query.getParam();
        String name = (String)param.get("name");
//        String roleId = (String)param.get("roleId");

        Page<Patient> page = new Page(1,2);
        page.setCurrent(query.getPageNum());
        page.setSize(query.getPageSize());

        LambdaQueryWrapper<Patient> lambdaQueryWrapper = new LambdaQueryWrapper();
        if(StringUtils.isNotBlank(name)){
            lambdaQueryWrapper.like(Patient::getPatientname,name);
        }
//        if(StringUtils.isNotBlank(roleId)){
//            lambdaQueryWrapper.eq(User::getRoleId,roleId);
//        }


        IPage result = patientService.page(page,lambdaQueryWrapper); //注意这里

        System.out.println("总记录"+result.getTotal());


        return Result.suc(result.getRecords(),result.getTotal());
    }

}
